﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using System.Web.Profile;
using System.Web.Security;
using MyBet.Web.Resources;
using System.Linq;
using ParieurPro.DAL.DatabaseModel;
using ParieurPro.DAL;

namespace MyBet.Web
{
    /// <summary>
    ///   RIA Services Domain Service that exposes methods for performing user
    ///   registrations.
    /// </summary>
    [EnableClientAccess]
    public class BetService : DomainService
    {
        /// <summary>
        /// Return the number of tournaments created
        /// </summary>
        /// <returns></returns>
        public int GetNumberOfTournaments()
        {
            //TODO : Implements read in database
            return 1;
        }

        /// <summary>
        /// </summary>
        /// <returns></returns>
        public List<TeamObject> GetTeams()
        {
            List<TeamObject> returnedList=null;
            using (MyBetDBEntities dbContext = new MyBetDBEntities())
            {
                returnedList = TeamObject.LoadTeamsObject(dbContext);
            }
            return returnedList;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public List<ChampionshipObject> GetChampionships()
        {
            using (MyBetDBEntities dbContext = new MyBetDBEntities())
            {
                List<ChampionshipObject> returnedList = new List<ChampionshipObject>();
                var query = (from championship in dbContext.Championships
                             select championship);
                IList<Championships> championships = query.ToList();
                foreach (Championships c in championships)
                {
                    ChampionshipObject champion;
                    champion = ChampionshipObject.CopyFromDatabaseObject(c);
                    returnedList.Add(champion);
                }
                return returnedList;
            }
        }

    }
}